'use strict'
const CMD = require("child_process");
/**
 * 执行cmd语句
 * @param {String} state  具体执行的命令
 */
function exec(state) {
  let start = new Date().getTime();
  console.log(state);
  let stdout = CMD.execSync("chcp 65001 | " + state);
  console.log("finish: " + (new Date().getTime() - start) + " mills" );
  // CMD.exec(state,(err, stdout, stderr) => {
  //   if(err) {
  //     console.log(err);
  //   }else if(stderr){
  //     console.log(stderr);
  //   }else {
  //     // console.log(stdout);
  //   }
  //   console.log("finish: " + (new Date().getTime() - start) + " mills" );
  // })
} 
/**
 * 拼接ffmpeg命令
 * @param {String} mp3      音频文件地址 
 * @param {String} mp4      视频文件地址
 * @param {String} saveName 生成的MP4文件 
 * @returns {String}
 */
function setCmdStr(mp3,mp4,saveName) {
  // ffmpeg -i vi.m4s -i au.m4s -codec copy wz.mp4
  if(mp3 && mp4) {
    return `ffmpeg -i ${mp3} -i ${mp4} -codec copy ${saveName}`;
  }else if(mp3) {
    return `ffmpeg -i ${mp3} -codec copy ${saveName}`;
  }else if(mp4) {
    return `ffmpeg -i ${mp4} -codec copy ${saveName}`;
  }
}
// String.prototype.replaceAll = function(s1,s2){
//   return this.replace(new RegExp("//" + s1 + "//","gm"),s2);
// }


module.exports = {
  exec,
  setCmdStr,
};